import 'package:flutter/material.dart';
import 'package:get/get.dart';

import '../../utils/httputils/api.dart';
import '../../utils/httputils/resultdata.dart';
import 'index.dart';
import 'models/ListWork.dart';

class AttractController extends GetxController with GetSingleTickerProviderStateMixin {
  AttractController();

  final state = AttractState();

  // tap
  void handleTap(int index) {
    Get.snackbar(
      "标题",
      "消息",
    );
  }

  /// 在 widget 内存中分配后立即调用。
  @override
  void onInit() {
    super.onInit();
    state.tabCtrl = TabController(length: 2, vsync: this, initialIndex: 0);
    listWorks();
  }



  listWorks() async{
    var params = {'entity': {'areaCode': "project_area_0"}, 'query': {'pageNum': 1, 'pageSize': 20, 'sortField': "", 'sortOrder': ""}};

    ResultData response = await Api.listWorks(params);

    if (response.isSuccess) {
      state.contents.clear();

      List _data = response.data['content'];
      state.contents = _data.map((e) => Content.fromJson(e)).toList();

      // state.listWork = ListWork.fromJson(response.data);

      update();
    }
  }


  /// 在 onInit() 之后调用 1 帧。这是进入的理想场所
  @override
  void onReady() {
    super.onReady();
  }

  /// 在 [onDelete] 方法之前调用。
  @override
  void onClose() {
    super.onClose();
  }

  /// dispose 释放内存
  @override
  void dispose() {
    super.dispose();
  }
}
